﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using System.Collections;

namespace InversPong.Model
{
    public class Bat : Object
    {
        public static readonly int[] defaultBatSize = new int[2] { 15, 70 };
        public static readonly int defaultBatSpeed = 4;

        public static readonly int maxBonus = 3;

        public decimal Speed { get; set; }

        private List<PowerUp> powerUps;

        public Vector2 InitialPosition { get; set; }

        public Bat(Vector2 position, String gfxName)
            : base(position, gfxName, Bat.defaultBatSize[0], Bat.defaultBatSize[1])
        {
            InitialPosition = position;
            powerUps = new List<PowerUp>();
            Speed = Bat.defaultBatSpeed;
        }

        public IList<PowerUp> GetPowerUps()
        {
            return powerUps;
        }

        public void AddPowerUp(PowerUp powerUp)
        {
            if (powerUp != null)
            {
                if (powerUps.Count >= maxBonus)
                {
                    powerUps.RemoveAt(0);
                }
                powerUps.Add(powerUp);
            }
            else
            {
                throw new ArgumentNullException("Bat can not have a null powerUp");
            }
        }

        public void RemovePowerUp(PowerUp.Types type) 
        {
            powerUps.RemoveAll(x => x.Type == type);
        }

        public void RemoveAllPowerUps()
        {
            powerUps.Clear();
        }

        public void RemoveUnavailablesPowerUps()
        {
            powerUps.RemoveAll(x => x.Timer == TimeSpan.Zero);
        }

        public bool ContainsPowerUp(PowerUp.Types type)
        {
            foreach (PowerUp powerUp in powerUps)
            {
                if (powerUp.Type == type)
                {
                    return true;
                }
            }
            return false;
        }
    }
}
